package com.blogsystem.controller;

import com.blogsystem.service.ArticleService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/api/stat")
public class StatController {

    @Autowired
    private ArticleService articleService;

    /**
     * 获取系统统计数据（文章数、用户数、点击量等）
     */
    @GetMapping
    public String getStat(Model model) {
        long articleCount = articleService.count();

        Map<String, Object> stat = new HashMap<>();
        stat.put("articleCount", articleCount);

        model.addAttribute("stat", stat);

        return "admin/stat"; // 返回视图名称
    }
}